//Sight.txt
//Written by Lazarus
//Each turn checks to see if terrain can see a location within a rectangle
//If it can, swaps to a new floor, if not, leaves floor alone.
//
//Also has script snipersentry built in. If you want to use sight, just delete the rest of it.
//
//Memory Cells
//Cell 0/1 - X,Y coordinates of northwest
//Cell 2/3 - X,Y coordinates of southeast
//Cell 4 - Normal floor(if can't see)
//Cell 5 - Floor to change(if can see)
//Cell 6/7- SDF to depend on (needs to be clear, and one greater needs to be clear as well. Ex. if (8,5), then leave (8,6) clear.

beginterrainscript;
variables;
short ox,oy,mx,my,i,px,py,target,tick,x,y;
body;

beginstate init_state;
tick = -1;
set_script_mode(3);
break;

beginstate start_state;

if(get_flag(get_memory_cell(6),get_memory_cell(7)) == 1) {
	x = get_memory_cell(0);
	while (x <=  get_memory_cell(2)) {
		y = get_memory_cell(1);
		while (y <= get_memory_cell(3)) 
		{	if(get_floor(x,y) == (get_memory_cell(5)))
				if(can_see_loc(x,y) == 0)
					set_floor(x,y,get_memory_cell(4));
			if(can_see_loc(x,y) == 1)  {
				set_floor(x,y,get_memory_cell(5)); }
				y = y + 1; }
				x = x + 1; }
}


break;

beginstate SEARCH_STATE;
break;